package com.amor.util


object PathUtil {

    //连接URL 字符串
    fun contactURL(vararg texts: String): String {
        val sb = StringBuilder()
        for (text in texts) {
            if (sb.isEmpty()) {
                sb.append(text)
                continue
            }
            val endSeparator = sb.endsWith("/")
            if (text.startsWith("/")) {
                if (endSeparator)
                    sb.append(text.substring(1, text.length))
                else
                    sb.append(text)
            } else {
                if (!endSeparator)
                    sb.append("/")
                sb.append(text)
            }
        }
        return sb.toString()
    }

    fun checkFileURL(text: String?): String? {
        if (text.isNullOrEmpty()) return null
        if (text.contains("://")) return text
        val host = ""
        return contactURL(host, text)
    }
}